#!/bin/sh
# The Sway configuration file in ~/.config/sway/config calls this script.
# You should see changes to the status bar after saving this script.
# If not, do "killall swaybar" and $mod+Shift+c to reload the configuration.

# more font awesome fonts are here: https://fontawesome.com/cheatsheet?from=io
# Battery empty 
# battery quarter 
# battery half 
# battery full 
# wifi 
# file image  I could use this after I take a screen shot
# 🐦 dovecot is running

# Produces "21 days", for example
#uptime_formatted=$(uptime | cut -d ',' -f1  | cut -d ' ' -f4,5)

# function start_vpn () {
#     nmcli connection up my_expressvpn_switzerland_udp
#     ls
# }

# vpn_connection=$(nmcli con show --active | grep my_expressvpn_switzerland_udp | awk '{ print $1 }')

vpn_connection=false

volume_level=$(pactl list sinks | grep "Volume: front-left" | awk '{print $5}')
# cut off the last character of the volume level which is '%'
volume_level=${volume_level%?}

if [ $volume_level -lt 10 ]
then
    volume_icon="<span foreground=\"#323232\">_</span>🔇 <span foreground=\"#323232\">_</span>"
elif [ $volume_level -lt 50 ]
then
    volume_icon="<span foreground=\"#323232\">_</span>🔉 <span foreground=\"#323232\">_</span>"
else
    volume_icon="<span foreground=\"#323232\">_</span> 🔊 <span foreground=\"#323232\">_</span>"
fi

# The abbreviated weekday (e.g., "Sat"), followed by the ISO-formatted date
# like 2018-10-06 and the time (e.g., 14:01)
date_formatted=$(date "+%H:%M %a %b %d %Y")

# Get the Linux version but remove the "-1-ARCH" part
linux_version=$(uname -r | cut -d '-' -f1)
#linux_version="kernel ${linux_version}"

# Returns the battery status: "Full", "Discharging", or "Charging".
battery_status=$(cat /sys/class/power_supply/BAT0/status)

# old command nmcli network connectivity check
internet_connected=$(nmcli network connectivity)
if [ $vpn_connection = "my_expressvpn_switzerland_udp" ]
then
    internet_icon="<span foreground=\"#323232\">_</span> 🖧 "
elif [ $internet_connected = "full" ]
then
    #start_vpn
    internet_icon="<span foreground=\"green\" size=\"large\"></span>"
elif [ $internet_connected = "limited" ]
then
    #start_vpn
    internet_icon="<span foreground=\"yellow\" size=\"large\"></span>"
elif [ $internet_connected = "portal" ]
then
    #start_vpn
    internet_icon="<span foreground=\"pink\" size=\"large\"></span>"
elif [ $internet_connected = "none" ]
then
    internet_icon="<span foreground=\"red\" size=\"large\"></span>"
elif [ $internet_connected = "unknown" ]
then
    internet_icon="<span foreground=\"red\" size=\"large\">⁈⁈</span>"
fi

big_space="<span foreground=\"#323232\">________________________</span>"

small_space="<span foreground=\"#323232\">___________</span>"

smallest_space="<span foreground=\"#323232\">_</span>"

status_line="$date_formatted $big_space 🐧 $linux_version $small_space "
# $uptime_formatted ↑
# Emojis and characters for the status bar 💎 💻 💡 🔌 ⚡ 📁 \|
echo $status_line $internet_icon $volume_icon 🔋 $battery_status
